Microsoft Technologies Currency, Date, এবং Number Formatting গাইড ও নোট

425

Currency, Date, এবং Number Formatting হল গুরুত্বপূর্ণ ফিচার যা ইউজার ইন্টারফেস (UI) ডেভেলপমেন্টে ব্যবহারকারীর ভ্যালু বা ডেটা ভালোভাবে প্রদর্শন করতে সাহায্য করে। WPF এবং WinUI অ্যাপ্লিকেশনে এই ফর্ম্যাটিং ফিচারগুলি ডেটাকে আরো পাঠযোগ্য এবং স্থানীয় কনভেনশনের সাথে সামঞ্জস্যপূর্ণ করে তোলে।

এই টিউটোরিয়ালে আমরা Currency, Date, এবং Number Formatting এর বিস্তারিত ব্যবহার এবং উদাহরণ দেখাবো।


১. Currency Formatting

Currency Formatting ব্যবহারকারীর অ্যাপ্লিকেশনে সংখ্যাকে মুদ্রার (Currency) ফর্ম্যাটে প্রদর্শন করতে সাহায্য করে। এটি একটি নির্দিষ্ট দেশের মুদ্রা সিম্বল এবং দশমিক পয়েন্ট ব্যবহার করে অর্থের মানের সঠিক উপস্থাপন করে।

WPF-এ Currency Formatting উদাহরণ

<Window x:Class="CurrencyFormattingExample.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Currency Formatting Example" Height="350" Width="525">
    <Grid>
        <TextBlock Text="{Binding CurrencyAmount, StringFormat={}{0:C}}" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="24"/>
    </Grid>
</Window>

C# কোড:

using System.Globalization;
using System.Windows;

namespace CurrencyFormattingExample
{
    public partial class MainWindow : Window
    {
        public decimal CurrencyAmount { get; set; }

        public MainWindow()
        {
            InitializeComponent();
            CurrencyAmount = 1234.56m;
            DataContext = this;
        }
    }
}

ব্যাখ্যা:

  • StringFormat={}{0:C}: এখানে C ব্যবহার করা হয়েছে, যা ডিফল্টভাবে দেশের মুদ্রা সিম্বল এবং দশমিকের সঠিক ফরম্যাট অনুসারে মান প্রদর্শন করবে (যেমন, $1,234.56 বা ₹1,234.56)।
  • CurrencyAmount: এটি একটি ডেসিমাল ভ্যালু যা মুদ্রার মান প্রদর্শন করবে।

২. Date Formatting

Date Formatting ডেটাকে স্থানীয় কনভেনশনের অনুসারে উপস্থাপন করতে ব্যবহৃত হয়, যেমন পূর্ণ তারিখ (e.g., "Sunday, December 1, 2024") বা কেবল মাস, দিন, বছর (e.g., "12/01/2024")।

WPF-এ Date Formatting উদাহরণ

<Window x:Class="DateFormattingExample.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Date Formatting Example" Height="350" Width="525">
    <Grid>
        <TextBlock Text="{Binding CurrentDate, StringFormat={}{0:D}}" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="24"/>
    </Grid>
</Window>

C# কোড:

using System;
using System.Windows;

namespace DateFormattingExample
{
    public partial class MainWindow : Window
    {
        public DateTime CurrentDate { get; set; }

        public MainWindow()
        {
            InitializeComponent();
            CurrentDate = DateTime.Now;
            DataContext = this;
        }
    }
}

ব্যাখ্যা:

  • StringFormat={}{0:D}: এখানে D ফরম্যাটটি সম্পূর্ণ তারিখের ফরম্যাটে ডেটা প্রদর্শন করবে, যেমন "Sunday, December 1, 2024"।
  • CurrentDate: এটি বর্তমান তারিখ ধারণ করে, যা DateTime.Now দ্বারা সেট করা হয়েছে।

DateTime Format Options:

  • D: পূর্ণ তারিখ (e.g., "Sunday, December 1, 2024")
  • d: সংক্ষিপ্ত তারিখ (e.g., "12/01/2024")
  • t: সংক্ষিপ্ত সময় (e.g., "12:30 PM")
  • T: পূর্ণ সময় (e.g., "12:30:00 PM")

৩. Number Formatting

Number Formatting সংখ্যা প্রদর্শনের জন্য বিভিন্ন ফরম্যাটিং ব্যবহার করে, যেমন দশমিক স্থান, হাজারের বিভাজক, শতাংশ এবং অন্যান্য।

WPF-এ Number Formatting উদাহরণ

<Window x:Class="NumberFormattingExample.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Number Formatting Example" Height="350" Width="525">
    <Grid>
        <TextBlock Text="{Binding NumberValue, StringFormat={}{0:N2}}" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="24"/>
    </Grid>
</Window>

C# কোড:

using System.Windows;

namespace NumberFormattingExample
{
    public partial class MainWindow : Window
    {
        public double NumberValue { get; set; }

        public MainWindow()
        {
            InitializeComponent();
            NumberValue = 1234567.89123;
            DataContext = this;
        }
    }
}

ব্যাখ্যা:

  • StringFormat={}{0:N2}: এখানে N2 ব্যবহার করা হয়েছে, যা সংখ্যাটিকে হাজারের বিভাজক এবং দশমিক স্থান সহ ২ দশমিক পর্যন্ত প্রদর্শন করবে (যেমন: "1,234,567.89")।
  • NumberValue: এটি একটি ডাবল ভ্যালু যা ১২৩৪৫৬৭.৮৯১২৩ নম্বরটি ধারণ করে।

Number Format Options:

  • N: হাজারের বিভাজক সহ সংখ্যা (e.g., "1,234,567.89")
  • F: দশমিক স্থান সহ পূর্ণসংখ্যা (e.g., "1234.56")
  • P: শতাংশ (e.g., "50%")
  • E: বৈজ্ঞানিক নোটেশন (e.g., "1.23E+03")

৪. Combining All Formatting

আপনি Currency, Date, এবং Number Formatting একসাথে ব্যবহার করতে পারেন একটি একক টেমপ্লেটে, যাতে একটি সম্পূর্ণ ফরম্যাটেড স্ট্রিং তৈরি হয়।

উদাহরণ: সমস্ত ফরম্যাটিং একসাথে ব্যবহার করা

<Window x:Class="AdvancedFormattingExample.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Advanced Formatting Example" Height="350" Width="525">
    <Grid>
        <TextBlock>
            <TextBlock.Inlines>
                <Run Text="{Binding CurrencyAmount, StringFormat={}{0:C}}"/>
                <Run Text=" " />
                <Run Text="{Binding CurrentDate, StringFormat={}{0:D}}"/>
                <Run Text=" " />
                <Run Text="{Binding NumberValue, StringFormat={}{0:N2}}"/>
            </TextBlock.Inlines>
        </TextBlock>
    </Grid>
</Window>

C# কোড:

using System;
using System.Windows;

namespace AdvancedFormattingExample
{
    public partial class MainWindow : Window
    {
        public decimal CurrencyAmount { get; set; }
        public DateTime CurrentDate { get; set; }
        public double NumberValue { get; set; }

        public MainWindow()
        {
            InitializeComponent();
            CurrencyAmount = 1234.56m;
            CurrentDate = DateTime.Now;
            NumberValue = 1234567.89123;
            DataContext = this;
        }
    }
}

আউটপুট:

  • CurrencyAmount: $1,234.56 (বা দেশীয় মুদ্রার সিম্বল)
  • CurrentDate: Sunday, December 1, 2024
  • NumberValue: 1,234,567.89

উপসংহার

Currency, Date, এবং Number Formatting ব্যবহার করে আপনার অ্যাপ্লিকেশনে ডেটাকে আরও পাঠযোগ্য এবং ব্যবহারকারী-বান্ধব করে তোলা সম্ভব। WPF এবং WinUI তে StringFormat এবং DataTemplate ব্যবহার করে আপনি ডেটার ফরম্যাটিংকে আরও কাস্টমাইজ এবং কার্যকরভাবে পরিচালনা করতে পারবেন।

এই টেকনিক্সগুলো ব্যবহার করে আপনি আপনার অ্যাপ্লিকেশনের UI-তে ডেটা উপস্থাপন এবং ডেটা টেমপ্লেট এবং কাস্টম ফরম্যাটিং ব্যবহার করে আরো উন্নত ইউজার ইন্টারফেস তৈরি করতে পারবেন।

Content added By
Promotion

Are you sure to start over?

Loading...